package com.xms.configuration.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.xms.configuration.entity.Settings;
import com.xms.core.exception.XmsException;
import com.xms.datacore.service.UpdaterService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.SQLException;
import java.util.List;

/**
 * <p>
 * SettingUpdaterService
 * </p>
 *
 * @author migo
 * @since 2021/10/22
 */
@CacheConfig(cacheNames = "settings", keyGenerator = "CacheKeyGenerator")
@Service
public class SettingUpdaterService extends UpdaterService<Settings> implements ISettingUpdaterService {
    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean update(Settings entity) throws XmsException, SQLException {
        return super.updateById(entity);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean updateMany(List<Settings> entity) throws XmsException, SQLException {
        return false;
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean update(Wrapper<Settings> updateWrapper) {
        return super.update(updateWrapper);
    }

    @CacheEvict(allEntries = true, condition = "#result == true")
    @Transactional(rollbackFor=Exception.class)
    @Override
    public boolean update(Settings entity, Wrapper<Settings> updateWrapper) {
        return super.update(entity, updateWrapper);
    }
}
